'use strict';

const Controller = require('egg').Controller;

class LoginController extends Controller {
  async login() {
    const {ctx,app} = this;
    const loginservice = app.weapp.LoginService.create(ctx.request,ctx.response);
    const data = await loginservice.login()
    if (data){
        ctx.code = 200;
        ctx.body = data.userInfo;
    }else{
        ctx.code = 301;
        ctx.body = 'database error';
    }
    ctx.body = data;
  }

  async getUserInfo(){
    const {ctx,app} = this;
    const loginservice = app.weapp.LoginService.create(ctx.request,ctx.response);
    const data = await loginservice.check();
    const result = await ctx.service.customer.saveCustomer(data.userInfo);
    if (result){
        ctx.code = 200;
        ctx.body = data.userInfo;
    }else{
        ctx.code = 301;
        ctx.body = 'database error';
    }
  }
}

module.exports = LoginController;
